//
// Created by ASUS on 2024/4/12/0012.
//
#include <bits/stdc++.h>
using namespace std;

struct Point{
	int x,y;
	Point()=default;
	Point(int _x, int _y) : x(_x), y(_y) {}
	Point operator-(const Point& p) const{
		return {x-p.x, y-p.y};
	}
};

double cross(Point p1, Point p2){
	return p1.x*p2.y-p1.y*p2.x;
}

double dis(Point& p1, Point& p2){
	return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}

//class Point{
//public:
//	Point() = default;
//	Point(int _x, int _y, double _angle) : x(_x), y(_y), angle(_angle) {}
//	Point operator-(const Point& p) const{
//		return {x-p.x, y-p.y,0};
//	}
//	double operator*(const Point& p) const{
//		return x*p.y-y*p.x;
//	}
//	static double dis(Point p1, Point p2){
//		return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
//	}
//
//	int x{}, y{};
//	double angle{};
//};


vector<vector<int>> convex_hull(vector<vector<int>>& points) {
    int n=points.size();
	sort(points.begin(),points.end(),[](auto&a,auto&b){
		if(a[1]==b[1]) return a[0]<b[0];
		return a[1]<b[1];
	});
	Point p0(points[0][0],points[0][1]);
	vector<Point> P;
	for(int i=1;i<n;i++){
		P.emplace_back(points[i][0],points[i][1]);
	}
	sort(P.begin(),P.end(),[&](auto&p1,auto&p2){
		if(atan2(p1.y-p0.y,p1.x-p0.x)==atan2(p2.y-p0.y,p2.x-p0.x)){
			return dis(p1,p0)<dis(p2,p0);
		}
		return atan2(p1.y-p0.y,p1.x-p0.x)<atan2(p2.y-p0.y,p2.x-p0.x);
	});
	Point pend(P.back().x,P.back().y);
	vector<Point> st;
	st.push_back(p0);
	for(Point&p:P){
		while(st.size()>1&&cross(st.back()-*next(st.rbegin()),p-st.back())<0) st.pop_back();
		st.push_back(p);
		if(p.x==pend.x&&p.y==pend.y) break;
	}
	vector<vector<int>> res;
	for(Point&p:st){
		res.push_back({p.x,p.y});
	}
	return res;
}

int main(){
//	vector<vector<int>> points = {{1,1},{2,2},{2,0},{2,4},{3,3},{4,2}};
	vector<vector<int>> points = {{3,0},{4,0},{5,0},{6,1},{7,2},{7,3},{7,4},{6,5},{5,5},{4,5},{3,5},{2,5},{1,4},{1,3},{1,2},{2,1},{4,2},{0,3}};
	vector<vector<int>> res = convex_hull(points);
	cout<<"size:"<<res.size()<<endl;
	for(auto&p:res){
		cout<<p[0]<<" "<<p[1]<<endl;
	}
	return 0;
}